//
//  Ext+UIBarButtonItem.swift
//  FZQSinLangWeiBo
//
//  Created by fuzhiqiang on 17/1/17.
//  Copyright © 2017年 fzq. All rights reserved.
//

import UIKit
//相当于分类方法
extension UIBarButtonItem{
    convenience init(imageName: String? = nil,title: String? = nil,target: Any?,action: Selector) {
        self.init()
        //实例化按钮
        let btn = UIButton()
        //添加点击事件
        btn.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        //设置带图片的按钮
        if let img = imageName {
            btn.setImage(UIImage(named: img), for: UIControlState.normal)
            btn.setImage(UIImage(named: "\(img)_highlighted"), for: UIControlState.highlighted)
        }
        //只有文字的按钮
        if let tit = title {
            btn.setTitle(tit, for: UIControlState.normal)
            btn.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
            btn.setTitleColor(FZQThemeColor, for: UIControlState.highlighted)
            btn.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        }
        //设置size
        btn.sizeToFit()
        customView = btn
    }
}
